/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package projet2_ro;

/**
 * This Class represents a sum, a boolean array and the sum's weight. A True in the array represents that the element of our multi-set at this index is contained in the sum
 * @author Houdemer and Rigon
 */
public class Somme implements Cloneable{

    boolean[] forme_binaire;
    int poids;

    /**
     * Constructor initializes the array with false
     * @param taille The array size ( our multi-set's cardinal )
     * @param poids The sum's weight
     */
    public Somme (int taille, int poids){
        this.poids=poids;
        forme_binaire= new boolean[taille];
        for(int i=0; i<taille; i++) forme_binaire[i]=false;
    }

    /**
     * Represents the fact we are adding an element of our multi-set in our sum
     * @param indice The index of the element we're adding
     */
    public void add(int indice){
        forme_binaire[indice]=true;
    }

    /**
     * Removes an element from the sum
     * @param indice The index of the element we're removing
     */
    public void remove(int indice){
        forme_binaire[indice]=false;
    }

    /**
     * Creates a copy of the "Somme"
     * @return The Copy
     */
    public Somme clone(){
       Somme s= new Somme(forme_binaire.length, poids);
       for(int i=0; i<forme_binaire.length; i++){
           if(forme_binaire[i])
               s.add(i);
        }
       return s;
    }

    public String toString(){
        String res="";

        res=res+"Somme a "+poids+" : ";
        for(int i=0; i<forme_binaire.length; i++){
            if(forme_binaire[i])
                res=res+"1";
            else
                res=res+"0";
        }
        return res+"\n";
    }

    /**
     * Same as the other toString except that this one does not print the weight to avoid repetition when used at a specific time
     * @param b Only here to override the other toString
     * @return The String
     */
    public String toString(boolean b){
        String res="";
        for(int i=0; i<forme_binaire.length; i++){
            if(forme_binaire[i])
                res=res+"1";
            else
                res=res+"0";
        }
        return res+"\n";
    }

    /**
     * A get Method
     * @return The boolean Array
     */
    public boolean[] getTab(){
        return forme_binaire;
    }

    /**
     * A get method
     * @return The weight
     */
    public int getPoids(){
        return poids;
    }
}
